package com.zhentao.controller;

import com.zhentao.dto.ForgetPasswordDto;
import com.zhentao.dto.LoginFormDTO;
import com.zhentao.dto.UpdatePwdDto;
import com.zhentao.service.UserService;
import com.zhentao.user.User;
import com.zhentao.utils.ResponseResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/user")
public class UserController {
    @Resource
    UserService userService;
    /**
     * 用户登录
     * @param user
     * @return ResponseResult
     */
    @PostMapping("/loginUser")
    public ResponseResult login(User user){
        return userService.login(user);
    }

    /**
     * 获取当前登录用户
     * @return ResponseResult
     */
    @PostMapping("/userinfo")
    public ResponseResult userInfo(){
        return userService.userInfo();
    }

    /**
     * 管理员登录
     * @param loginFormDTO
     * @return ResponseResult
     */
    @PostMapping("/loginManage")
    public ResponseResult loginManage(LoginFormDTO loginFormDTO){
        return userService.adminLogin(loginFormDTO);
    }

    /**
     * 修改密码-用户端
     * @param updatePwdDto
     * @return ResponseResult
     */
    @PostMapping("/updatePassword-user")
    public ResponseResult updatePassword(UpdatePwdDto updatePwdDto){
        return userService.updatePassword(updatePwdDto);
    }

    /**
     * 发送验证码
     * @return ResponseResult
     * */
    @PostMapping("/sendCaptcha")
    public ResponseResult sendCaptcha(){
        return userService.sendCaptcha();
    }

    /**
     * 忘记密码
     * @param forgetPasswordDto
     * @return ResponseResult
     * */
    @PostMapping("/forgetPassword")
    public ResponseResult forgetPassword(ForgetPasswordDto forgetPasswordDto){
        return userService.forgetPassword(forgetPasswordDto);
    }


    /**
     * 退出登录
     * @return ResponseResult
     * */
    @GetMapping("/logout")
    public ResponseResult logout(String token){
        return userService.logout(token);
    }



}
